package com.tencent.wxcloudrun.schedule;

import java.util.Objects;

import javax.annotation.Resource;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.tencent.wxcloudrun.manager.ActiManager;
import com.tencent.wxcloudrun.service.TActiService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Ryan Zhao
 *         <p>
 *         Copyright: Copyright (c) 2023
 *         </p>
 * @version 1.0
 * @date 2023-08-22 12:21
 * @description: 活动开始任务
 */
@Slf4j
@Component
public class ActiBeginJob implements Job {

    @Resource
    private ActiManager actiManager;

    @Resource
    private TActiService actiService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void execute(JobExecutionContext jobExecutionContext) {
        String actiIdStr = Objects.toString(jobExecutionContext.getJobDetail().getJobDataMap().get("param"));
        Long actiId = Long.valueOf(actiIdStr);
        log.info("活动开始定时任务-处理开始-活动序号=[{}]", actiId);

        // 活动开始
        actiService.actiBegin(actiId);

        // 更新缓存
        actiManager.saveRedis4Acti(actiId, false);

        log.info("活动开始定时任务-处理成功");
    }
}
